/***************************************************************************
 *   Copyright (C) 2008 by Eduardo Gurgel Pinho                            *
 *   edgurgel@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef __CYLINDER_H__
#define __CYLINDER_H__

#include "object.h"
#include "math/vector.h"
#include "math/ray.h"
#include "material/object_material.h"

#include <boost/tuple/tuple.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/version.hpp>

using namespace boost::tuples;

namespace Sirat {

namespace Object {

class Cylinder : public Object {
public:
	Cylinder(Material::Object_Material* _object_material,const Math::Vector&,const Math::Vector&,const double,const double);
	Cylinder();
	Cylinder(const Cylinder& _cylinder);
	~Cylinder();

	Math::Vector get_center() const;
	Math::Vector get_direction() const;
	double get_radius() const;
	double get_height() const;
	virtual Math::Vector get_normal(const Math::Vector&) const;

	void set_center(const Math::Vector&);
	void set_direction(const Math::Vector&);
	void set_radius(const double);
	void set_height(const double);

	virtual tuple<double,Math::Vector,Object*> intersection(const Math::Ray&);

	virtual tuple<double,double> get_u_v(const Math::Vector& _point) const;
	
	Cylinder& operator=(const Cylinder& _cylinder);

	Object* clone() { return new Cylinder(*this); }
	
private:
	friend class boost::serialization::access;
	template<class Archive> void serialize(Archive&, const unsigned int);

	Math::Vector center;
	Math::Vector direction;
	double radius;
	double height;
};



template<class Archive> void Cylinder::serialize(Archive& ar, const unsigned int /* file_version */){
	ar	& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Object)
		& BOOST_SERIALIZATION_NVP(center)
		& BOOST_SERIALIZATION_NVP(direction)
		& BOOST_SERIALIZATION_NVP(radius)
		& BOOST_SERIALIZATION_NVP(height);              
}

}

}

#endif
